package com.hsteach.web.controller.calendar;

import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.common.utils.SecurityUtils;
import com.hsteach.dao.domain.calendar.Calendar;
import com.hsteach.enums.BooleanEnum;
import com.hsteach.service.calendar.CalendarService;
import com.hsteach.web.controller.calendar.dto.UpdateCalendarDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 周行事历主Controller
 * 
 * @author fanxquer
 * @date 2023-11-28
 */
@Api(value = "周行事历H5", tags = "周行事历H5")
@RestController
@RequestMapping("/calendar")
public class CalendarH5Controller extends BaseController
{
    @Autowired
    private CalendarService calendarService;

    /**
     * 查询周行事历主列表
     */
    @ApiOperation("查询周行事历")
    @GetMapping()
    public TableDataInfo list()
    {
        Calendar query = new Calendar();
        query.setDelStatus(BooleanEnum.TRUE.getCode());
        query.setOrgCode(SecurityUtils.getAuthInfo().getOrgCode());
        List<Calendar> list = calendarService.selectCalendarList(query);
        List<UpdateCalendarDto> ret = list.stream().map(e -> {
            UpdateCalendarDto vo = new UpdateCalendarDto();
            BeanUtils.copyProperties(e, vo);
            return vo;
        }).collect(Collectors.toList());
        return getDataTable(ret);
    }

    /**
     * 获取周行事历主详细信息
     */
    @ApiOperation("查询周行事历日历明细-H5")
    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Long id)
    {
        return success(calendarService.getMonthCalendar(id));
    }

}
